home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / xpk_source / oberon / examples / xsum.mod < prev    next >
Text File  |  1998-08-27  |  2KB  |  69 lines

  1. (*************************************************************************
  2.  
  3. :Program.    XSum.mod
  4. :Contents.   sums up all bytes in a compressed or uncompressed file
  5. :Author.     Hartmut Goebel [hG]
  6. :Language.   Oberon
  7. :Translator. Amiga Oberon V2.25
  8. :History.    V0.9, 09 Jan 1992 Hartmut Goebel [hG]
  9. :History.    V1.0, 11 Jul 1992 [hG] ·now more Oberon-like :-)
  10. :Date.       11 Jul 1992 15:12:20
  11.  
  12. *************************************************************************)
  13.  
  14. MODULE XSum;
  15.  
  16. IMPORT
  17.   io,
  18.   arg:= Arguments,
  19.   e  := Exec,
  20.   s  := SYSTEM,
  21.   u  := Utility,
  22.   xpk:= XpkMaster;
  23.  
  24. (* This is a typical read-and-process xpk application. Try it out... XSum a
  25.  * file, then compress it and XSum it again. The result should be the same.
  26.  *)
  27.  
  28. VAR
  29.   OutBuf: POINTER TO ARRAY MAX(LONGINT)-1 OF CHAR;
  30.   OutLen, OutBufLen, i: LONGINT;
  31.   Sum: LONGINT;
  32.   Arg: e.STRING;
  33.   ErrBuf: ARRAY xpk.errMsgSize+1 OF CHAR;
  34.  
  35.  
  36. PROCEDURE End(text: ARRAY OF CHAR);
  37. BEGIN
  38.   io.WriteString(text); io.WriteLn;
  39.   HALT(10);
  40. END End;
  41.  
  42. BEGIN
  43.   Sum := 0; i := 0;
  44.  
  45.   IF arg.NumArgs() # 1 THEN End("Usage: XSum <filename>"); END;
  46.   arg.GetArg(1,Arg);
  47.  
  48.   IF 0 # xpk.UnpackTags(
  49.            xpk.inName,      s.ADR(Arg),      (* The file name to be read              *)
  50.            xpk.getError,    s.ADR(ErrBuf),   (* A pointer to the error message buffer *)
  51.            xpk.getOutBuf,   s.ADR(OutBuf),   (* Sets a pointer to the output buffer   *)
  52.            xpk.getOutLen,   s.ADR(OutLen),   (* Sets the number of bytes written      *)
  53.            xpk.getOutBufLen,s.ADR(OutBufLen),(* Sets the length of the output buffer  *)
  54.            xpk.passThru,    e.true,          (* Will pass through uncompressed data   *)
  55.            u.done)
  56.   THEN End(ErrBuf); END;
  57.  
  58.   REPEAT
  59.     INC(Sum,ORD(OutBuf[i]));
  60.     INC(i);
  61.   UNTIL i = OutLen;
  62.   io.WriteInt(Sum,0); io.WriteLn;
  63.  
  64. CLOSE
  65.   IF OutBuf # NIL THEN e.FreeMem(OutBuf,OutBufLen); END;
  66.  
  67. END XSum.
  68.  
  69.